using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class Player : ViewController
	{
		public float MovementSpeed = 5;

		public static Player Default;
        private void Awake()
        {
			Default = this;
        }

        private void OnDestroy()
        {
			Default = null;
        }

        void Start()
		{
			// Code Here
			"Hello QFramework".LogInfo();

			HurtBox.OnTriggerEnter2DEvent(Collider2D =>
			{
				var hitBox = Collider2D.GetComponent<HitBox>();
				if (hitBox)
				{
					if (hitBox.Owner.CompareTag("Enemy"))
					{
						this.DestroyGameObjGracefully();


						//Time.timeScale = 0;
						UIKit.OpenPanel<UIGameOverPanel>();
					}
				}



			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

        private void Update()
        {
			var horizontal = Input.GetAxis("Horizontal");
			var vertical = Input.GetAxis("Vertical");

			//normalized ????????????????????????????????????
			var direction = new Vector2(horizontal, vertical).normalized;

			SelfRigidbody2D.velocity = direction * MovementSpeed;

        }


    }
}
